-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WIP/RFC: Adding EgalDict{K,V} (aka ObjectIdDict{K,V}) #24932
Conversation
The repl-test failure was my bad (I dropped the fallback of |
No, this is ok as one line after there is the check whether the converted key is |
X-ref: #9381 (comment) a Edit: reading through #9381, I think it would make sense to change |
+1 for |
I'm not a fan of copying code like this. For the purpose of #24354, it would be sufficient just to add type parameters to |
Me neither, although note that it is "only" the type-def of I could DRY this up by tomorrow by moving the fields of I will also do the rename |
Strange error in test/inference.jl
I started the DRY-up. |
I have to say I'm not thrilled with the name |
base/dict.jl
Outdated
age::UInt | ||
idxfloor::Int # an index <= the indexes of all used slots | ||
maxprobe::Int | ||
mutable struct Dict{K,V} <: HashDict{K,V} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not mutable. also, we should optimize to remove the allocation for this case (since it would be relatively trivial), but currently don't, so we may need to make sure the perf regression is minor in the meantime.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, not mutable, thanks. And I was not aware of the perf problem. I'll run it against JuliaCI/BaseBenchmarks.jl#150 and some against older perf-tests.
Yes, I'll rename: |
Playing devil's advocate, |
Internally IdDicts are only used early in the bootstrap. All other instances of ObjectIdDict use my new implementation. Skipping CIs as I expect tests to fail. I will force push a working commit onto this tomorrow. [ci skip] [av skip] [bsd skip]
Ok, so I DRY-ed this up (apart from unifying WeakKeyDict) and renamed Todo:
|
|
?module works ?sin does not rehashing the meta-dicts fixes it for m in Base.Docs.modules Base.rehash!(Base.Docs.meta(m)) end Simlarly, there was a rehashing in serialize.jl which was fixed going ObjectIdDict->IdDict. But with the doc-system that did not help. Skipping some CIs to save resources: [ci skip] [av skip] [bsd skip]
The current state of this PR has an issue with dicts not being re-hashed at times. This shows with the doc-system, where The other issue is performance. I ran these somewhat primitive and probably not exhaustive tests: https://gist.github.com/mauro3/ada59b1fd9a09202631edccf255c4e1b (results at the bottom). They show performance degraded some 10-20% for Dict and WeakKeyDict. The new ObjectIdDict is about 3x slower than I will not have much time to work on this over the weekend. The breaking change of this PR is the |
I'm pretty confused by the approach here. Why rename |
Yes, you're right, I got confused. Let's call the new one |
Replaced by #25210 |
Jeff's comment that a
ObjectIdDict
with type parameters would be good to have, prompted me to look into this again. It is inspired by my previous effort #7348.In this PR I added that requested ObjectIdDict-like dict, called
EqualDict{K,V}
. This PR is not the DRY-est (e.g.WeakKeyDict
should be unified too), but my idea was to keep it as simple as possible to allow rapid review of this PR. That may would make the inclusion of this and (hopefully) thus #24354 before the imminent feature freeze possible. I would be happy to DRY this up a bit later in a separate PR.The PR does the following:
Associative{K,V} :> AbstractDict{K,V} :> Dict{K.V}
which is the supertype of all dicts based around the current machinery ofDict
. Currently all subtypes ofAbstractDict
would need to have the same fields asDict
(but this could be dried up by using aDictStore
type and have that as a field).isequalkey(h, k1, k2)
which compares two keys for a given dicth
keyhash(h, k)
which produces a hash for keyk
of dicth
EgalDict
is then implemented by copying theDict
type-def and setting:isequalkey(::EgalDict, k1, k2) = k1===k2
keyhash(::EgalDict, k) = object_id(k)
Questions on which further work on this PR depend:
Things to ponder:
ObjectIdDict
toCore
and/or not export it anymore. (If I understand correctly, it needs to stay as it is in the C-part of Julia, but I might be wrong.) Maybe call itCore.OIdDict
.EgalDict{K,V}
could beObjectIdDict{K,V}
and most code using it should just work.TODO:
EgalDict
Possible future DRY-ups: